<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>三岁博客后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="icon" href="../../static/images/favicon.ico" th:href="@{/images/favicon.ico}"/>
    <link rel="stylesheet" href="../../../static/lib/admin/lib/layui-v2.6.3/css/layui.css" th:href="@{/lib/admin/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" href="../../../static/lib/admin/css/public.css" media="all" th:href="@{/lib/admin/css/public.css}">
    <link rel="stylesheet" href="../../../static/lib/editormd/css/editormd.min.css" th:href="@{/lib/editormd/css/editormd.min.css}"><!--MD编辑器css-->


</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>公告发布</legend>
        </fieldset>

        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">公告标题</label>
                <div class="layui-input-block">
                    <input type="text" name="notitle" lay-verify="notitle" autocomplete="off" placeholder="请输入公告标题"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <div class="required stackable field">
                    <div id="md-content" style="z-index: 1 !important;">
                        <textarea placeholder="公告内容" name="notice" lay-verify="notice"  style="display: none"></textarea>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="create">立即发布</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script><!--引入jquery js-->
<script src="../../../static/lib/editormd/editormd.min.js" th:src="@{/lib/editormd/editormd.min.js}"></script><!--MD编辑器JS-->
<script src="../../static/lib/admin/lib/layui-v2.6.3/layui.js" th:src="@{/lib/admin/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script src="../../static/lib/admin/js/lay-config.js?v=1.0.4" th:src="@{/lib/admin/js/lay-config.js?v=1.0.4}" charset="utf-8"></script>


<script th:inline="javascript">
    var contentEditor;
    contentEditor = editormd("md-content", {
        width: "100%",
        height: 640,
        syncScrolling: "single",
        path: /*[[@{/lib/editormd/lib/}]]*/ "../../../static/lib/editormd/lib/"
    });
</script>

<script>

    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit;

        //自定义验证规则
        form.verify({
            notitle: function (value) {
                if (value == null || value == '') {
                    return '请输入公告标题';
                }
            }
            , notice: function (value) {
                if (value == null || value == '') {
                    return '请输入公告内容';
                }
            }
        });

        //监听提交
        form.on('submit(create)', function (data) {
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // })

            $.ajax({
                url: '../../page/notice/create',
                type: 'post',
                dataType: 'json',
                contentType:'application/json;charset=utf-8',
                data: JSON.stringify(data.field),
                success: function (suc) {
                    if (suc.code == 200) {
                        layer.alert(suc.msg, {icon: 1,cancel: function(){
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                                //刷新页面
                                parent.location.reload();
                            }}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新页面
                            parent.location.reload();
                        });
                    } else {
                        layer.alert(suc.msg, {icon: 5});
                    }
                }
            });


            return false;
        });
    });
</script>

</body>
</html>